<ui:composition template="/WEB-INF/templates/customer/base.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

	<ui:define name="title">GiftList</ui:define>

	<ui:define name="content">
		<h:form>
			<div style="text-align: right;">
				<h:link value="Condividi" outcome="/giftList">
					<f:param name="userId" value="#{giftListBean.currentId}"/>
				</h:link>
			</div>
			<p:fragment autoUpdate="true">
				<ui:repeat var="element" value="#{giftListBean.giftElements}">
					<p:dataTable var="paid" value="#{element.paid}">
						<f:facet name="header">
							<h:outputText value="#{element.cartPackage.model.name}" />
						</f:facet>

						<p:column headerText="Id">
							<h:outputText value="#{paid.product.id}" />
						</p:column>

						<p:column headerText="Nome">
							<h:outputText value="#{paid.product.name}" />
						</p:column>

						<p:column headerText="Prezzo">
							<h:outputText value="#{paid.product.price * element.cartPackage.quantity}" />
						</p:column>

						<p:column headerText="Acquista">
							<p:commandButton value="Acquista"
								rendered="#{ paid.quantity lt element.cartPackage.quantity }" action="#{giftListBean.pay(element, paid)}" />
							<h:outputText value="Acquistato" rendered="#{ ! ( paid.quantity lt element.cartPackage.quantity ) }" />
						</p:column>
					</p:dataTable>
				</ui:repeat>
			</p:fragment>
		</h:form>
	</ui:define>
</ui:composition>
